<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<script>	
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {   
	initDetail();
});



function initDetail(){
	var sendFlag = ${sendFlag};
	if(sendFlag=="1"){
		//新增
		$("#btnModify").hide();
		$("#btnDelete").hide();
		$("#btnSave").show();
		$("#btnCancle").hide();
	}else if(sendFlag=="2"){
		//查询
		$("#btnModify").show();
    	$("#btnDelete").show();
    	$("#btnSave").hide();
    	$("#btnCancle").hide();
		disabledDictAll();
	}
}

function disabledDictAll(){
	$("#entryDetailForm input[type='text']").attr("disabled",true);
	$("#entryDetailForm input[type='textarea']").attr("disabled",true);
	$("#entryDetailForm textarea").attr("disabled",true);
}

function enabledDictAll(){
	$("#entryDetailForm input[type='text']").attr("disabled",false);
	$("#entryDetailForm input[type='textarea']").attr("disabled",false);
	$("#entryDetailForm textarea").attr("disabled",false);
	$("#entryDictCode").attr("readonly",true);
}


//取消修改
function cancle(){
	var iscancle=window.confirm("确定取消修改？");
	if(iscancle==true){
		document.entryDetailForm.reset();
		disabledDictAll();
		$("#btnModify").show();
		$("#btnDelete").show();
		$("#btnSave").hide();
		$("#btnCancle").hide();
	}
	else{
		return;
	}
}
//时间控件
$( "#createTime" ).datepicker({
	showOtherMonths: true,
	selectOtherMonths: false,
	dateFormat:'yy-mm-dd',
});

$( "#updateTime" ).datepicker({
	showOtherMonths: true,
	selectOtherMonths: false,
	dateFormat:'yy-mm-dd',
}); 

function save(){
	
	//校验保存的必填数据项
	$("#entryDetailForm").validate({
	    errorElement: 'div',
	    errorClass: 'help-block',
	    focusInvalid: false,
	    rules: {
	    	entryDictCode: {
	          required: true
	       },
	       entryDictName: {
	          required: true
	       }
	    },
	    messages: {
	    	entryDictName: {
	           required: "字典值不能为空！"
	        },
	    	entryDictCode: {
	           required: "字典编码不能为空！"
	        } 
	    },
	
	    highlight: function (e) {
	        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
	    },
	    success: function (e) {
	        $(e).closest('.form-group').removeClass('has-error').addClass('has-info');
	        $(e).remove();
	    },
	    errorPlacement: function (error, element) {
	        error.insertAfter(element.parent());
	    }
	});
	
	if ($("#entryDetailForm").valid() == false) {
		return;
	}
	var sendFlag = $("#openFlag").val();
	//alert(sendFlag);
   	var urlVal = "${ctx}/dict/saveEntry.do";
   	if(sendFlag==3){
   	    //修改路径
   	    urlVal = "${ctx}/dict/updateEntry.do";
   	}
   	//alert(urlVal);
	saveEntryInfo(urlVal);
}
//异步保存信息
function saveEntryInfo(urlVal){
	var params = {
		"dictType":$("#entryDictType").val(),
		"dictOrder":$("#entryDictOrder").val(),
		"dictCode":$("#entryDictCode").val(),
		"dictValue":$("#entryDictName").val(),
		"remarks":$("#entryRemark").val(),
		"createBy":$("#creater").val(),
		"createDate":$("#createTime").val(),
		"updateBy":$("#updater").val(),
		"updateDate":$("updateTime").val()
	};
	var param = {"dictType":$("#entryDictType").val()};
	enabledDictAll();
	 $.ajax({
        	async : false,
	    	url: urlVal,
	    	type:"post",
	    	data: $.param(params),
	    	dataType:"json", 
	    	success: function(data){				    					    		
			   	if(data[0]=="ok"){
			   		alert(data[1]);
			   		$("#openFlag").val("2");
				   	initDetail();
				    $("#addEntryInfo").dialog("close");
				    $("#entryDetailInfo").show();
				   	$("#entryDetailInfo").load("${ctx}/dict/entryList.do",param); 
			   	}else{
			   		alert(data[1]);
			   	}
	    	}
       	}); 
}


//修改字典表信息
function modify(){
		$("#btnModify").hide();
		$("#btnDelete").hide();
		$("#btnSave").show();
		$("#btnCancle").show();
		$("#openFlag").val("3");
		enabledDictAll();
	}
</script>
<div id="tab1" class="row">
	<div class="col-xs-12">
	 <form name="entryDetailForm" id="entryDetailForm" class="form-horizontal" role="form">
	  <input type="hidden" id="openFlag" name="sendFlag" value="${sendFlag}" />
	   <input type="hidden" id="dictEntry" name="dictEntry" value="${dictType}" />
	   
		<div class="row" >
		  <div class="form-group col-xs-12">
	       		<label class="col-sm-3 control-label no-padding-left" for="entryDictType">字典编码<font color="red">*</font></label>
				<div class="col-sm-9">
				  <div class="clearfix">
				  	<input type="text" class="col-xs-10  can-modify"  id="entryDictType" name="entryDictType"  value="${sysDictEntry.dictType}" readonly/>
	              </div>
	            </div>
	       </div>
		</div>
		<div class="row" >
			<div class="form-group col-xs-12">
	       		<label class="col-sm-3 control-label no-padding-left" for="dictDesc">字典顺序</label>
				<div class="col-sm-9">
				  <div class="clearfix">
				  	<input type="text" id="entryDictOrder" class="col-xs-10  can-modify"  name="entryDictOrder"  value="${sysDictEntry.dictOrder}" readonly/>
	              </div>
	            </div>
		    </div>  
		</div>
		<div class="row">
			<div class="form-group col-xs-12">
	       		<label class="col-sm-3 control-label no-padding-left" for="entryDictCode">字典码<font color="red">*</font></label>
				<div class="col-sm-9">
				  <div class="clearfix">
				  	<input type="text" class="col-xs-10  can-modify" id="entryDictCode" name="entryDictCode"  value="${sysDictEntry.dictCode}" maxlength="10"/>
	              </div>
	            </div>
	       </div> 
		</div>
		<div class="row" >
	       <div class="form-group col-xs-12">
	       		<label class="col-sm-3 control-label no-padding-left" for="entryDictName">字典值<font color="red">*</font></label>
				<div class="col-sm-9">
				  <div class="clearfix">
				  <input type="text" class="col-xs-10  can-modify" id="entryDictName" name="entryDictName" value="${sysDictEntry.dictValue}" maxlength="30" />
	      		  </div>
	      		</div>
	       </div>
		</div>
		
		<div class="row" >
		 <div class="form-group col-xs-12">
		       		<label class="col-sm-3 control-label no-padding-left" for="entryRemark">备注</label>
					<div class="col-sm-8">
					  <div class="clearfix">
						<textarea class="limited form-control can-modify" id="entryRemark" name="entryRemark" maxlength="160">${sysDictEntry.remarks}</textarea>
		      		  </div>
		      		</div>
		       </div>
		</div>
	</form>
	</div>
</div>	
